package xml

import groovy.xml.MarkupBuilder
import groovy.xml.StreamingMarkupBuilder

//使用多行字符串
map=["冰与火之歌":["马丁","200",2019],"java编程思想":["大神","89",2018]]
content=''
map.each {key,value->
    element="""
    <book name="${key}">
        <author>${value[0]}</author>
        <year>${value[2]}</year>
        <price>${value[1]}</price>
    </book>
    """
    content += element
}
xml01="<bookstore>${content}</bookstore>"
println xml01
//使用MarkupBuilder ,非常适合同步构建简单的XMl文档
def out =   new StringWriter()
def xml02 = new MarkupBuilder(out) //不指定输出,默认会打印控制台
xml02.bookstore(){
    book(name:"希尔山庄"){
        author '作家'
        year '2018'
        price 49
    }
    book(name:"Groovy程序设计"){
        author(value:"大牛")
        year(value:"2019")
        price(value:"49")
    }
}
println out


